<template>
  <div class="home">
    <!-- 输入框 -->
    <Title class="title" />
    <Swiper :swiperData="swiperData" />
    <!-- nav导航栏 -->
    <div class="flexbox">
      <div @click="$router.push({ name: 'list', params: { type: 'true' } })">
        <van-icon name="shop-o" />
        <p>整租</p>
      </div>
      <div @click="$router.push({ name: 'list', params: { type: 'false' } })">
        <van-icon name="friends-o" />
        <p>合租</p>
      </div>
      <div>
        <van-icon name="location-o" @click="$router.push('/map')" />
        <p>地图找房</p>
      </div>
      <div>
        <van-icon name="search" @click="$router.push('/rent/add')" />
        <p>去出租</p>
      </div>
    </div>
    <!-- 租房小组 -->
    <div class="group">
      <div class="subtitle">
        <p>租房小组</p>
        <span>更多</span>
      </div>
      <ul>
        <li v-for="item in groupsListData" :key="item.id">
          <div class="pic">
            <img :src="`http://liufusong.top:8080${item.imgSrc}`" alt="" />
          </div>
          <div class="word">
            <p>{{ item.title }}</p>
            <p>{{ item.desc }}</p>
          </div>
        </li>
      </ul>
    </div>
    <!-- 最新资讯 -->
    <div class="news">
      <div class="newstitle">最新资讯</div>
      <div class="newsList" v-for="item in newsListDate" :key="item.id">
        <div class="pic">
          <img :src="`http://liufusong.top:8080${item.imgSrc}`" alt="" />
        </div>
        <div class="context">
          <div>
            <h3>{{ item.title }}</h3>
          </div>
          <p class="time">
            <i>{{ item.from }}</i
            >{{ item.date }}
          </p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapState } from 'vuex'
import Title from '@/components/Title'
import Swiper from '@/components/Swiper'
export default {
  name: 'Home',
  data () {
    return {}
  },
  components: {
    Title,
    Swiper
  },
  created () {
    this.getHomeListInfo()
  },
  methods: {
    async getHomeListInfo () {
      this.$Toast.loading({
        duration: 0,
        forbidClick: true,
        message: '加载中...'
      })
      await this.$store.dispatch('confirmPicture')
      await this.$store.dispatch('groupsInfo', {
        area: localStorage.getItem('code')
      })
      await this.$store.dispatch('newsInfo', localStorage.getItem('code'))
      this.$Toast.clear()
    }
  },
  computed: {
    ...mapState({
      swiperData: (state) => state.home.picture || [],
      groupsListData: (state) => state.home.groupsList || [],
      newsListDate: (state) => state.home.newsList || []
    })
  }
}
</script>

<style lang="less" scoped>
.home {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  position: relative;
  // 输入框
  .title {
    position: absolute;
    z-index: 999;
    top: 20px;
    left: 20px;
  }
  // 租房
  .flexbox {
    display: flex;
    justify-content: space-around;
    align-items: center;
    height: 122px;
    div {
      text-align: center;
      .van-icon {
        width: 50px;
        background-color: rgb(235, 252, 236);
        height: 50px;
        border-radius: 50%;
        font-size: 35px;
        line-height: 50px;
        color: #43b978;
      }
      p {
        margin-top: 10px;
        font-size: 14px;
        color: #333;
      }
    }
  }
  // 租房小组
  .group {
    width: 100%;
    height: 188px;
    background-color: #f6f5f6;
    padding: 15px;
    .subtitle {
      display: flex;
      height: 30px;
      width: 100%;
      justify-content: space-between;
      font-size: 15px;
      span {
        color: #787d82;
        font-size: 14px;
      }
      p {
        font-weight: 600;
      }
    }
    ul {
      display: flex;
      flex-wrap: wrap;
      justify-content: space-between;
      li {
        width: 160px;
        height: 60px;
        background-color: #fff;
        margin-bottom: 10px;
        border-radius: 3px;
        display: flex;
        justify-content: space-evenly;
        align-items: center;
        .pic {
          width: 60px;
          height: 60px;
          img {
            width: 100%;
          }
        }
        .word {
          p {
            font-size: 14px;
          }
        }
      }
    }
  }
  // 最新资讯
  .news {
    padding: 0 10px 50px;
    .newstitle {
      width: 100%;
      height: 45px;
      line-height: 45px;
      font-size: 15px;
      font-weight: bold;
    }
    .newsList {
      display: flex;
      align-items: center;
      width: 100%;
      height: 100px;
      padding: 15px 0;
      border-bottom: 0.5px solid #ccc;
      .pic {
        width: 106px;
        height: 80px;
        img {
          width: 100%;
          height: 100%;
        }
      }
      .context {
        height: 80px;
        margin-left: 15px;
        h3 {
          color: #394043;
          font-size: 15px;
          width: 230px;
          margin-bottom: 5px;
        }
        p {
          font-size: 12px;
          display: flex;
          justify-content: space-between;
          color: #afb2b3;
          margin-bottom: 3px;
          width: 230px;
          height: 15px;
          margin-top: 23px;
        }
      }
    }
  }
}
</style>
